<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            查询工单
        </div>
    </header>
    <script id="chkBillTemp" type="text/x-dot-template">

        {{~ it:value:index}}
        <li class="aui-list-item" onclick="setOrder('{{= it[index].workOrder }}','{{= it[index].mrlCode }}','{{= it[index].lotCode }}','{{= it[index].mrlName }}','{{= it[index].mrlGid }}');">
            <div class="aui-media-list-item-inner">
                <div class="aui-list-item-inner ">
                    <div class="aui-list-item-text">
                        <div class="aui-list-item-title aui-font-size-14">
                            工单号：{{= it[index].workOrder }}
                        </div>
                    </div>
                    <div class="aui-list-item-text aui-font-size-12">
                        产线：{{= it[index].workCenter }}
                    </div>
                    <div class="aui-list-item-text aui-font-size-12">
                        班次：{{= it[index].workShift }}
                    </div>
                    <div class="aui-list-item-text aui-font-size-12">
                        计划开始日期：{{= it[index].dataTime }}
                    </div>
                    <div class="aui-list-item-text aui-font-size-12">
                        物料号：{{= it[index].mrlCode }}
                    </div>
                    <div class="aui-list-item-text aui-font-size-12">
                        物料名：{{= it[index].mrlName }}
                    </div>
                </div>
            </div>
        </li>
        {{~}}

    </script>

    <div class="aui-content" style="margin-top:50px;">
        <div class="aui-form" style="margin-top:15px;">
            <div class="aui-content aui-margin-b-15">
                <ul class="aui-list aui-form-list">
                    <li class="aui-list-item">
                        <div class="aui-list-item-inner">
                            <div class="aui-list-item-label">产线</div>
                            <select id="workCenter">
                            </select>
                        </div>
                    </li>
                    <li class="aui-list-item">
                        <div class="aui-list-item-inner">
                            <div class="aui-list-item-label">班次</div>
                            <select id="workShift">
                            </select>
                        </div>
                    </li>

                    <li class="aui-list-item">
                        <div class="aui-list-item-inner">
                            <div class="aui-list-item-label" style="width:150px">计划开始日期</div>
                            <div class="aui-list-item-input" onclick="timePicker();">
                                <input type="text" placeholder="选择日期" style="padding-left: 35px;" class="aui-input"
                                    id="dateTime">
                            </div>
                        </div>
                    </li>

                    <li class="aui-list-item">
                        <div class="aui-list-item-inner">
                            <div class="aui-list-item-label" style="width:150px">物料</div>
                            <div class="aui-list-item-input">
                                <input type="text" placeholder="物料" style="padding-left: 35px;" class="aui-input"
                                    id="mrlCode">
                            </div>
                        </div>
                    </li>



                </ul>
            </div>
        </div>
    </div>
    <div style="width:100%;margin-top:2%;"></div>
    <div class="aui-btn aui-btn-info aui-btn-block" onclick="doSearch()">查询</div>
    <div class="aui-content aui-margin-b-15">
        <ul class="aui-list aui-media-list" id="taskList">

        </ul>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/doT.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript">
    //光标所在id
    var idSelector = "";
    var boxnum = "";
    apiready = function () {
        selectWorkCell();
        selectWorkShift();
    };
    //查询产线位置下拉框
    function selectWorkCell() {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/selectWorkCell";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var map = eval("(" + data + ")");
                var list = eval(map.list);
                var html = "<option value=''>--请选择--</option>";
                for (var i = 0; i < list.length; i++) {
                    html += "<option value='" + list[i].code + "'>" + list[i].name + "</option>";
                }
                $api.html($api.byId("workCenter"), html);
            }
        });

    }

    //查询班次下拉框
    function selectWorkShift() {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/selectWorkShift";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var map = eval("(" + data + ")");
                var list = eval(map.list);
                var html = "<option value=''>--请选择--</option>";
                for (var i = 0; i < list.length; i++) {
                    html += "<option value='" + list[i].code + "'>" + list[i].name + "</option>";
                }
                $api.html($api.byId("workShift"), html);
            }
        });

    }


    //时间选择器
    function timePicker() {
        api.openPicker({
            type: 'date',
            date: new Date(),
            title: '选择日期'
        }, function (ret, err) {
            if (ret) {
                var monthTemp = (ret.month < 10 ? '0' + ret.month : ret.month);
                var dayTemp = (ret.day < 10 ? '0' + ret.day : ret.day);
                var date = ret.year + "-" + monthTemp + "-" + dayTemp;
                $("#dateTime").val(date);
                doSearch();
            }
        });
    }
    // 获取光标所在组件的id
    function getIdSelector() {
        var e = event || window.event;
        var el = e.srcElement || e.target;
        idSelector = el.id;
        $("#" + el.id).select();
    }


    //查询资源维护任务
    function doSearch() {

        //箱号
        var workCenter = $("#workCenter").val();
        var dateTime = $("#dateTime").val();
        var mrlCode = $("#mrlCode").val();
        var workShift = $("#workShift").val();

        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getMdWorkOrder";
        var data = {
            values: {
                workCenter: workCenter,
                mrlCode:mrlCode,
                un: un,
                dateTime: dateTime,
                shiftCode:workShift
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == '0') {
                    var list = eval(myobj.list);

                    var evaluation = doT.template($api.dom('#chkBillTemp').innerHTML);
                    $api.dom('#taskList').innerHTML = evaluation(list);

                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }

    //选则返回函数
    function setOrder(workOrder, mrlCode, lotCode, mrlName, mrlGid) {
        api.closeWin();
        var name = api.pageParam.name;
        api.execScript({
            name: 'qcmChkBillCreateac',
            script: 'setOrder("' + workOrder + '","' + mrlCode + '","' + lotCode + '","' + mrlName  + '","' + mrlGid +'")'
        });
    }

    //返回按钮
    function closeWin() {
        api.closeWin({});
    }
</script>

</html>